<?
$formId = extractNumberWithKeyFromArray('formId', $_REQUEST, null);
$documentCode = extractNumberWithKeyFromArray('documentCode', $_REQUEST, null);
if ($documentCode) {
	$documentcontent = $cmsDocument->openDocument($documentCode);
}
else {
	$documentcontent = null;
}
?>
<div class="cms_browse_heading">
  <div class="cms_browse_heading_label">
    <h1>CMS Quick Links</h1>
  </div>
  <div class="cms_browse_addrecord"></div>
</div>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>
<form class="cms_form" action="/cms/html/index.php" method="post" enctype="multipart/form-data" name="CMS Quick Links" id="CMS Quick Links">
    <input type="hidden" name="processFormData" value="YES" />
	<input type="hidden" name="fileNo" value="2">
	<input type="hidden" name="documenttypecode" value="docCMSQuLink">
	<input type="hidden" name="formId" value="193">
	<input type="hidden" name="returnURL" value="<?= urlencode("/cms/html/index.php?fileNo=".FILE_BROWSE_QUICK_LINKS."&formid=193"); ?>">
	<?
	if (isset($documentCode) && $documentCode) {
	?>
	<input type="hidden" name="documentCode" value="<?= $documentCode; ?>">
	<?
	}
	?>
  <div class="cms_masteredit">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="cms_masteraddedit_table" >
	  <tr>
	    <td height="1" width="160"><img src="/cms/images/spacer.gif" height="1" width="160" /></td>
		<td height="1"><img src="/cms/images/spacer.gif" height="1" width="1" /></td>
	  </tr>
	  <tr id="cms_masteredit_193_10026" class="cms_masteraddedit_table"> 
	    <td id="cms_form_label_documentcode" class="cms_form_label" >Document Code:</td> 
		<td class="cms_form_element" align="left">
		  <span id="cms_form_documentcode" class="cms_form_textlabel" name="documentcode" ><?= $documentCode; ?></span>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_11343" class="cms_masteraddedit_table"> 
	    <td id="cms_form_label_categorycode" class="cms_form_label" >Group:</td> 
		<td class="cms_form_element" align="left">
		  <select name="categorycode" id="cms_form_categorycode" class="cms_form_dropdown">
		    <?
			$tableWriter = new CmsTableWriter("grouplist", $db);
			$tableWriter->resetCustomIterator("");
			while ($row = $tableWriter->nextItem()) {
				if (in_array($row->gid, groupsForUserId($authInfo->uid, $db))) {
					echo "<option value='".$row->gid."'";
					if (isset($documentcontent->categorycode) && $documentcontent->categorycode == $row->gid) {
						echo " SELECTED";
					}
					echo ">".magicClean($row->groupname)."</option>\n";
				}
			}
			?>
		  </select>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_10001" class="cms_masteraddedit_table">
	    <td id="cms_form_label_datelogged" class="cms_form_label" >Last Updated:</td> 
		<td class="cms_form_element" align="left">
		  <span id="cms_form_datelogged" class="cms_form_textlabel" name="datelogged" ><?= date("l d M Y H:i:s"); ?></span>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_11344" class="cms_masteraddedit_table"> 
	    <td id="cms_form_label_title" class="cms_form_label" >Link Text:</td> 
		<td class="cms_form_element" align="left">
		  <input type="text" name="title" value="<? if (isset($documentcontent->title)) echo magicClean($documentcontent->title); ?>" id="cms_form_title" class="cms_form_text"></input>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_11345" class="cms_masteraddedit_table"> 
	    <td id="cms_form_label_shortdescription" class="cms_form_label" >Link:</td> 
		<td class="cms_form_element" align="left">
		  <input type="text" name="shortdescription" value="<? if (isset($documentcontent->shortdescription)) echo magicClean($documentcontent->shortdescription); ?>" id="cms_form_shortdescription" class="cms_form_text"></input>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_11346" class="cms_masteraddedit_table"> 
	    <td id="cms_form_label_content" class="cms_form_label" >Rank:</td>
		<td class="cms_form_element" align="left">
		  <input type="text" name="content" value="<? if (isset($documentcontent->content)) echo magicClean($documentcontent->content); ?>" id="cms_form_content" class="cms_form_text"></input>
		</td>
	  </tr>
	  <tr id="cms_masteredit_193_11347" class="cms_masteraddedit_table"> 
	  <td id="cms_form_label_author" class="cms_form_label" >CMS Quick Link Category:</td> 
	  <td class="cms_form_element" align="left">
	    <select name="author" id="cms_form_author" class="cms_form_dropdown">
		  <?
		  $cmsDocument->flush();
		  $cmsDocument->addDocumentType("docCMSLnkCat");
		  if (!permissionForMode($authInfo->uid, CMS_GROUP_ADMIN, $db)) {
			  $cmsDocument->addConstraint("categorycode", $authInfo->uid);
			  $cmsDocument->addConstraint("categorycode", "");
			  $cmsDocument->addConstraint("categorycode", "<< NULL >>", "IS");
		  }
		  $cmsDocument->addSort("title");
		  $cmsDocument->resetIterator();
		  while ($row = $cmsDocument->nextDocument()) {
			  echo "<option value='".$row->documentcode."'";
			  if (isset($documentcontent->author) && $documentcontent->author == $row->documentcode) {
				  echo " SELECTED";
			  }
			  echo ">".magicClean($row->title)."</option>\n";
		  }
		  ?>
		</select>
	  </td>
	</tr>
	<tr id="cms_masteredit_193_11349" class="cms_masteraddedit_table"> 
	  <td id="cms_form_label_authordepartment" class="cms_form_label" >Short Description:</td> 
	  <td class="cms_form_element" align="left">
	    <textarea name="authordepartment" id="cms_form_authordepartment" class="cms_form_textarea"><? if (isset($documentcontent->authordepartment)) echo magicClean($documentcontent->authordepartment, false); ?></textarea>
	  </td>
	</tr>
		<?
		//Check if admin - show select box of users
		//Else add hidden field for the current user
		if (permissionForMode($authInfo->uid, CMS_GROUP_ADMIN, $db)) {
		?>
		<tr id="cms_masteredit_194_11350" class="cms_masteraddedit_table"> 
		  <td id="cms_form_label_organisationalname" class="cms_form_label" >User:</td> 
		  <td class="cms_form_element" align="left">
		    <select name="organisationalname" id="cms_form_organisationalname" class="cms_form_dropdown">
			  <option value="">All</option>
			  <?
			  $tableWriter = new CmsTableWriter("user", $db);
			  $tableWriter->resetCustomIterator(" ORDER BY username");
			  while ($row = $tableWriter->nextItem()) {
				  echo "<option value='".$row->uid."'";
				  if (isset($documentcontent->organisationalname) && $documentcontent->organisationalname == $row->uid) {
					  echo " SELECTED";
				  }
				  echo ">".$row->username."</option>\n";
			  }
			  ?>
			</select>
		  </td>
		</tr>
		<?
		}
		else {
		?>
		<input type="hidden" name="organisationalname" id="cms_form_organisationalname" value="<?= $authInfo->uid; ?>">
		<?
		}
		?>
    <tr id="cms_masteredit_193_11355" class="cms_masteraddedit_table"> 
	  <td id="cms_form_label_authorbio" class="cms_form_label" >Open in new window?</td> 
	  <td class="cms_form_element" align="left">
	  <input type="checkbox" name="authorbio" value="1" id="cms_form_authorbio" class="cms_form_checkbox" <? if (isset($documentcontent->authorbio) && $documentcontent->authorbio) echo " checked"; ?>></input>
	  </td>
	</tr>
	<tr>
	  <td colspan="2" align="right" valign="middle">
	    <script language="javascript" type="text/javascript"> function selectAllElementsInSelect( select ) { for (i=0; i < select.options.length; i++){ select.options[i].selected = true; } return; } function doOnSubmitForElementsOnForm( formName ){ f = document.getElementById( formName ); if (f != null){ for (j = 0; j < f.length; j++ ){ e = f[j]; if (e.onsubmit){ e.onsubmit(); } } } return; } </script>
		<a id="cms_form_submit_193" class="cms_form_submit" href="javascript:doOnSubmitForElementsOnForm('CMS Quick Links');document.forms['CMS Quick Links'].submit();" ><img src="/cms/images/button_go.gif" /></a>
	  </td>
	</tr>
  </table>
</form>
</div>
